package com.example.com.transcribeeditpublish.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.example.com.transcribeeditpublish.BR;
import com.example.com.transcribeeditpublish.R;
import com.example.com.transcribeeditpublish.databinding.ItemVideoMianBinding;

import java.util.List;

/**
 * Created by i7-1 on 2018/12/3.
 */

public class VideoRVBindingAdapter extends RecyclerView.Adapter<VideoRVBindingAdapter.VideoBindingHolder> {
    private Context context;
    private List<String> data;

    public VideoRVBindingAdapter(Context context, List<String> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public VideoBindingHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemVideoMianBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_video_mian, parent, false);
        return new VideoBindingHolder(binding);

    }

    @Override
    public void onBindViewHolder(VideoBindingHolder holder, int position) {
        holder.binding.setVariable(BR.entity, data.get(position));
        // 立刻刷新界面
        holder.binding.executePendingBindings();
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    class VideoBindingHolder extends RecyclerView.ViewHolder {
        public ItemVideoMianBinding binding;

        public VideoBindingHolder(ItemVideoMianBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
